package org.visionlibrary.image.filters.bluring;

import java.awt.Point;

import javax.media.jai.TiledImage;

import org.visionlibrary.image.model.WindowFilter;


public class MaxMin extends WindowFilter {
	protected int width;

	protected int height;

	public MaxMin(int width, int height) {
		this.width = width;
		this.height = height;
	}

	public MaxMin(int size) {
		this(size, size);
	}

	public MaxMin() {
		this(3);
	}

	protected int getNewPixelVal(TiledImage src, Point p, int channel) {
		int min = getWindowPixelVal(src, new Point(0, 0), channel);
		int max = min;

		Point pIter = new Point();
		for (pIter.y = 0; pIter.y < windowHeight; pIter.y++)
			for (pIter.x = 0; pIter.x < windowWidth; pIter.x++) {
				int val = getWindowPixelVal(src, pIter, channel);
				if (val < min)
					min = val;
				if (val > max)
					max = val;
			}

		return max - min;
	}

	/**
	 * Sets used window properties.
	 * 
	 * @see WindowFilter
	 */
	protected void setWindowProperties() {
		windowWidth = width;
		windowHeight = height;
		dstPointInWindow = new Point(width / 2, height / 2);
	}

}
